package org.sklse.learningassistant.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.sklse.learningassistant.bean.ResultModel;
import org.sklse.learningassistant.bean.User;
import org.sklse.learningassistant.repository.UserRepository;
import org.sklse.learningassistant.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;

@RestController
@RequestMapping(value = "user")
public class UserController {

    @Autowired
    private UserSerivce userSerivce;

    @ApiOperation(value = "登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public boolean userLogin(User login) throws ServletException {
        return userSerivce.login(login);
    }


    @ApiOperation(value = "注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "账号", required = true, dataType = "string"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "string"),
            //@ApiImplicitParam(name = "")
    })
    @PostMapping(value = "register")
    public boolean studnetRegister(User user) throws ServletException {
        return userSerivce.register(user);
    }

    @RequestMapping("exist")
    public boolean userNameExist(@RequestParam(name = "username") String username) {
        return userSerivce.exist(username);
    }
}
